package com.rong.DAO;

import com.opensymphony.xwork2.ActionContext;
import com.rong.hibernate.BaseHibernateDAO;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.Restrictions;

import com.rong.ORM.ZynBusiInputV;
import com.rong.ORM.ZynQueryCriter;
import com.rong.ORM.ZynTransfer;
import com.rong.ORM.ZynUser;

import com.rong.hibernate.Const;
/**
 * A data access object (DAO) providing persistence and search support for
 * ZynBusiInputV entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.rong.DAO.ZynBusiInputV
 * @author MyEclipse Persistence Tools
 */ 

public class ZynBusiInputVDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(ZynBusiInputVDAO.class);
	// property constants
	public static final String NUM = "num";
	public static final String HEAT_NUM = "heatNum";
	public static final String HEAT_COM_ID = "heatComId";
	public static final String HEAT_CAR_ID = "heatCarId";
	public static final String HEAT_PRICE_ID = "heatPriceId";
	public static final String HEAT_PRICE = "heatPrice";
	public static final String HEAT_SUM = "heatSum";
 	public static final String HEAT_DATE = "heatDate"; 
	public static final String HEAT_WTR_CM_TEPT = "heatWtrCmTept";
	public static final String HEAT_WTR_AF_TEPT = "heatWtrAfTept";
	public static final String WATER_IS = "waterIs";
	public static final String WATER_NUM = "waterNum";
	public static final String WATER_COM_ID = "waterComId";
	public static final String WATER_CAR_ID = "waterCarId";
	public static final String WATER_PRICE_ID = "waterPriceId";
	public static final String WATER_PRICE = "waterPrice";
	public static final String WATER_SUM = "waterSum";
	public static final String WATER_METER_STAR = "waterMeterStar";
	public static final String WATER_METER_END = "waterMeterEnd";
	public static final String EXT_ATTR1 = "extAttr1";
	public static final String EXT_ATTR2 = "extAttr2";
	public static final String EXT_ATTR3 = "extAttr3";
	public static final String EXT_ATTR4 = "extAttr4";
	public static final String EXT_ATTR5 = "extAttr5";
	public static final String EXT_ATTR6 = "extAttr6";
	public static final String EXT_ATTR7 = "extAttr7";
	public static final String EXT_ATTR8 = "extAttr8";

	public void save(ZynBusiInputV transientInstance) {
		log.debug("saving ZynBusiInputV instance");
		try {
			Transaction ts=null;
			ts=getSession().beginTransaction();
			getSession().save(transientInstance);
			ts.commit();
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(ZynBusiInputV persistentInstance) {
		log.debug("deleting ZynBusiInputV instance");
		try {
			Transaction ts=null;
			ts=getSession().beginTransaction();
			getSession().delete(persistentInstance);
			ts.commit();
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public ZynBusiInputV findById(java.lang.Integer id) {
		log.debug("getting ZynBusiInputV instance with id: " + id);
		try {
			getSession().clear();
			getSession().flush();
			ZynBusiInputV instance = (ZynBusiInputV) getSession().get(ZynBusiInputV.class, id); 
			return instance;   
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(ZynBusiInputV instance) {
		log.debug("finding ZynBusiInputV instance by example");
		try {
			List results = getSession().createCriteria(
					"com.rong.DAO.ZynBusiInputV").add(Example.create(instance))
					.list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ZynBusiInputV instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from ZynBusiInputV as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByNum(Object num) {
		return findByProperty(NUM, num);
	}

	public List findByHeatNum(Object heatNum) {
		return findByProperty(HEAT_NUM, heatNum);
	}

	public List findByHeatComId(Object heatComId) {
		return findByProperty(HEAT_COM_ID, heatComId);
	}

	public List findByHeatCarId(Object heatCarId) {
		return findByProperty(HEAT_CAR_ID, heatCarId);
	}

	public List findByHeatPriceId(Object heatPriceId) {
		return findByProperty(HEAT_PRICE_ID, heatPriceId);
	}

	public List findByHeatPrice(Object heatPrice) {
		return findByProperty(HEAT_PRICE, heatPrice);
	}

	public List findByHeatSum(Object heatSum) {
		return findByProperty(HEAT_SUM, heatSum);
	}
  	public List findByHeatDate(Object heatDate) {
 		return findByProperty(HEAT_DATE, heatDate);
 	}
	public List findByHeatWtrCmTept(Object heatWtrCmTept) {
		return findByProperty(HEAT_WTR_CM_TEPT, heatWtrCmTept);
	}

	public List findByHeatWtrAfTept(Object heatWtrAfTept) {
		return findByProperty(HEAT_WTR_AF_TEPT, heatWtrAfTept);
	}

	public List findByWaterIs(Object waterIs) {
		return findByProperty(WATER_IS, waterIs);
	}

	public List findByWaterNum(Object waterNum) {
		return findByProperty(WATER_NUM, waterNum);
	}

	public List findByWaterComId(Object waterComId) {
		return findByProperty(WATER_COM_ID, waterComId);
	}

	public List findByWaterCarId(Object waterCarId) {
		return findByProperty(WATER_CAR_ID, waterCarId);
	}

	public List findByWaterPriceId(Object waterPriceId) {
		return findByProperty(WATER_PRICE_ID, waterPriceId);
	}

	public List findByWaterPrice(Object waterPrice) {
		return findByProperty(WATER_PRICE, waterPrice);
	}

	public List findByWaterSum(Object waterSum) {
		return findByProperty(WATER_SUM, waterSum);
	}

	public List findByWaterMeterStar(Object waterMeterStar) {
		return findByProperty(WATER_METER_STAR, waterMeterStar);
	}

	public List findByWaterMeterEnd(Object waterMeterEnd) {
		return findByProperty(WATER_METER_END, waterMeterEnd);
	}

	public List findByExtAttr1(Object extAttr1) {
		return findByProperty(EXT_ATTR1, extAttr1);
	}

	public List findByExtAttr2(Object extAttr2) {
		return findByProperty(EXT_ATTR2, extAttr2);
	}

	public List findByExtAttr3(Object extAttr3) {
		return findByProperty(EXT_ATTR3, extAttr3);
	}

	public List findByExtAttr4(Object extAttr4) {
		return findByProperty(EXT_ATTR4, extAttr4);
	}

	public List findByExtAttr5(Object extAttr5) {
		return findByProperty(EXT_ATTR5, extAttr5);
	}

	public List findByExtAttr6(Object extAttr6) {
		return findByProperty(EXT_ATTR6, extAttr6);
	}

	public List findByExtAttr7(Object extAttr7) {
		return findByProperty(EXT_ATTR7, extAttr7);
	}

	public List findByExtAttr8(Object extAttr8) {
		return findByProperty(EXT_ATTR8, extAttr8);
	}

	public List findAll() {
		log.debug("finding all ZynBusiInputV instances");
		try {
			getSession().flush();
			getSession().clear();
			String queryString = "from ZynBusiInputV";
			Query queryObject = getSession().createQuery(queryString);
			
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public ZynBusiInputV merge(ZynBusiInputV detachedInstance) {
		log.debug("merging ZynBusiInputV instance");
		try {
			Transaction ts=null;
			ts=getSession().beginTransaction();
			ZynBusiInputV result = (ZynBusiInputV) getSession().merge(
					detachedInstance);
			ts.commit();
			getSession().flush();
			getSession().clear();
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(ZynBusiInputV instance) {
		log.debug("attaching dirty ZynBusiInputV instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(ZynBusiInputV instance) {
		log.debug("attaching clean ZynBusiInputV instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
	
	//以下为分页部分
	/**
	 * 查找并返回所有计划
	 */

	public List<ZynBusiInputV> findZynBusiInputVtByPage(int page, int rowsPerPage,ZynQueryCriter queryCrt) {
		
		String queryString = "from ZynBusiInputV";
		Transaction ts2=null;
		ts2=getSession().beginTransaction();
		getSession().clear(); 
		
		ActionContext actionContext = ActionContext.getContext();         
	     Map session = actionContext.getSession(); 
	     ZynUser loginUser=(ZynUser)session.get("loginUser");   //登录用户	
	     
		Criteria crt = getSession().createCriteria(ZynBusiInputV.class);
		crt.addOrder(org.hibernate.criterion.Order.desc("id"));
		
		if(queryCrt.getStartDate()!=null&&queryCrt.getEndDate()!=null){
			crt.add(Restrictions.and(Restrictions.ge("heatDate", new java.sql.Timestamp(queryCrt.getStartDate().getTime())), Restrictions.le("heatDate", new java.sql.Timestamp(queryCrt.getEndDate().getTime()))));
		}else if(queryCrt.getStartDate()!=null&&queryCrt.getEndDate()==null){
			crt.add(Restrictions.ge("heatDate", new java.sql.Timestamp(queryCrt.getStartDate().getTime())));	
		}else if(queryCrt.getStartDate()==null&&queryCrt.getEndDate()!=null){
			crt.add(Restrictions.le("heatDate", new java.sql.Timestamp(queryCrt.getEndDate().getTime())));	
		}
//		if(queryCrt.getToComId()!=null&&queryCrt.getToComId()>0){			
//			crt.add(Restrictions.eq("comToId", queryCrt.getToComId()));
//		}
		if(queryCrt.getFromComId()!=null&&queryCrt.getFromComId()>0){			
			crt.add(Restrictions.eq("heatComId", queryCrt.getFromComId()));
		}

		if(queryCrt.getCarId()!=null&&queryCrt.getCarId()>0){			
			crt.add(Restrictions.eq("heatCarId", queryCrt.getCarId()));
		}

		if(queryCrt.getNum()!=null&&!(queryCrt.getNum().equalsIgnoreCase(""))){						
			crt.add(Restrictions.eq("num",queryCrt.getNum()));
		
		}
		if(queryCrt.getHeatNum()!=null&&!(queryCrt.getHeatNum().equalsIgnoreCase(""))){			
			crt.add(Restrictions.eq("heatNum", queryCrt.getHeatNum()));
		}
		
		//--权限判断,分公司只能看本公司单据，本部可以查看全部		
		if(loginUser.getZyncom().getComProperty().equalsIgnoreCase(Const.comTypetop)){			
			//总部
		}else{			
			crt.add(Restrictions.eq("extattrint4", loginUser.getComId()));  //匹配单据的所属公司
		}
		
		crt.setMaxResults(rowsPerPage); // 每页最多显示几条
		crt.setFirstResult((page - 1) * rowsPerPage); // 每页从第几条记录开始
		ts2.commit();
		List<ZynBusiInputV> list = crt.list();
		for (int i = 0; i < list.size(); i++) {
			
			System.out.println("*****busi get heat****** id=:"+ list.get(i).getId()+list.get(i).getSellSts().getName());
		
		}
        
		

		return list;
	}
	/**
	 * 查找并返回所有计划
	 */

	public List<ZynBusiInputV> tatolRows(ZynQueryCriter queryCrt) {
		getSession().clear();

		ActionContext actionContext = ActionContext.getContext();         
	     Map session = actionContext.getSession(); 
	     ZynUser loginUser=(ZynUser)session.get("loginUser");   //登录用户	
		
		Criteria crt = getSession().createCriteria(ZynBusiInputV.class);
		crt.addOrder(org.hibernate.criterion.Order.desc("id"));
		

		if(queryCrt.getStartDate()!=null&&queryCrt.getEndDate()!=null){
			crt.add(Restrictions.and(Restrictions.ge("heatDate", new java.sql.Timestamp(queryCrt.getStartDate().getTime())), Restrictions.le("heatDate", new java.sql.Timestamp(queryCrt.getEndDate().getTime()))));
		}else if(queryCrt.getStartDate()!=null&&queryCrt.getEndDate()==null){
			crt.add(Restrictions.ge("heatDate", new java.sql.Timestamp(queryCrt.getStartDate().getTime())));	
		}else if(queryCrt.getStartDate()==null&&queryCrt.getEndDate()!=null){
			crt.add(Restrictions.le("heatDate", new java.sql.Timestamp(queryCrt.getEndDate().getTime())));	
		}
//		if(queryCrt.getToComId()!=null&&queryCrt.getToComId()>0){			
//			crt.add(Restrictions.eq("comToId", queryCrt.getToComId()));
//		}
		if(queryCrt.getFromComId()!=null&&queryCrt.getFromComId()>0){			
			crt.add(Restrictions.eq("heatComId", queryCrt.getFromComId()));
		}

		if(queryCrt.getCarId()!=null&&queryCrt.getCarId()>0){			
			crt.add(Restrictions.eq("heatCarId", queryCrt.getCarId()));
		}

		if(queryCrt.getNum()!=null&&!(queryCrt.getNum().equalsIgnoreCase(""))){						
			crt.add(Restrictions.eq("num",queryCrt.getNum()));
		
		}
		if(queryCrt.getHeatNum()!=null&&!(queryCrt.getHeatNum().equalsIgnoreCase(""))){			
			crt.add(Restrictions.eq("heatNum", queryCrt.getHeatNum()));
		}
		
		//--权限判断,分公司只能看本公司单据，本部可以查看全部		
		if(loginUser.getZyncom().getComProperty().equalsIgnoreCase(Const.comTypetop)){			
			//总部
		}else{			
			crt.add(Restrictions.eq("extattrint4", loginUser.getComId()));  //匹配单据的所属公司
		}
		List<ZynBusiInputV> list = crt.list();
		return list;
	}
	
	/**
	 * 查找并返回所有计划,采水单据明细
	 */

	public List<ZynBusiInputV> findZynBusiWatertByPage(int page, int rowsPerPage,ZynQueryCriter queryCrt) {
		
		String queryString = "from ZynBusiInputV";
		Transaction ts2=null;
		ts2=getSession().beginTransaction();
		getSession().clear(); 
		
		ActionContext actionContext = ActionContext.getContext();         
	     Map session = actionContext.getSession(); 
	     ZynUser loginUser=(ZynUser)session.get("loginUser");   //登录用户	
		
		Criteria crt = getSession().createCriteria(ZynBusiInputV.class);
		crt.addOrder(org.hibernate.criterion.Order.desc("id"));
		crt.add(Restrictions.eq("waterIs","true" ));  //必须标识 已经采水
		
		if(queryCrt.getStartDate()!=null&&queryCrt.getEndDate()!=null){
			crt.add(Restrictions.and(Restrictions.ge("waterDate", new java.sql.Timestamp(queryCrt.getStartDate().getTime())), Restrictions.le("waterDate", new java.sql.Timestamp(queryCrt.getEndDate().getTime()))));
		}else if(queryCrt.getStartDate()!=null&&queryCrt.getEndDate()==null){
			crt.add(Restrictions.ge("waterDate", new java.sql.Timestamp(queryCrt.getStartDate().getTime())));	
		}else if(queryCrt.getStartDate()==null&&queryCrt.getEndDate()!=null){
			crt.add(Restrictions.le("waterDate", new java.sql.Timestamp(queryCrt.getEndDate().getTime())));	
		}
//		if(queryCrt.getToComId()!=null&&queryCrt.getToComId()>0){			
//			crt.add(Restrictions.eq("comToId", queryCrt.getToComId()));
//		}
		if(queryCrt.getFromComId()!=null&&queryCrt.getFromComId()>0){			
			crt.add(Restrictions.eq("waterComId", queryCrt.getFromComId()));
		}

		if(queryCrt.getCarId()!=null&&queryCrt.getCarId()>0){			
			crt.add(Restrictions.eq("waterCarId", queryCrt.getCarId()));
		}

		if(queryCrt.getNum()!=null&&!(queryCrt.getNum().equalsIgnoreCase(""))){						
			crt.add(Restrictions.eq("num",queryCrt.getNum()));
		
		}
		if(queryCrt.getHeatNum()!=null&&!(queryCrt.getHeatNum().equalsIgnoreCase(""))){			
			crt.add(Restrictions.eq("waterNum", queryCrt.getHeatNum()));
		}
		//--权限判断,分公司只能看本公司单据，本部可以查看全部		
		if(loginUser.getZyncom().getComProperty().equalsIgnoreCase(Const.comTypetop)){			
			//总部
		}else{			
			crt.add(Restrictions.eq("extattrint4", loginUser.getComId()));  //匹配单据的所属公司
		}
		crt.setMaxResults(rowsPerPage); // 每页最多显示几条
		crt.setFirstResult((page - 1) * rowsPerPage); // 每页从第几条记录开始
		ts2.commit();
		List<ZynBusiInputV> list = crt.list();
		for (int i = 0; i < list.size(); i++) {
			
			System.out.println("*****busi get water****** in DAO... :"+ list.get(i).getId()+" status:"+list.get(i).getSellStswater().getId()+" name:"+list.get(i).getSellStswater().getName());
		
		}
        
		

		return list;
	}
	/**
	 * 查找并返回所有计划
	 */

	public List<ZynBusiInputV> WatertatolRows(ZynQueryCriter queryCrt) {
		getSession().clear();
		
		ActionContext actionContext = ActionContext.getContext();         
	     Map session = actionContext.getSession(); 
	     ZynUser loginUser=(ZynUser)session.get("loginUser");   //登录用户	
	     
		Criteria crt = getSession().createCriteria(ZynBusiInputV.class);
		crt.addOrder(org.hibernate.criterion.Order.desc("id"));
	   
		crt.add(Restrictions.eq("waterIs","true" ));  //必须标识 已经采水
		
		if(queryCrt.getStartDate()!=null&&queryCrt.getEndDate()!=null){
			crt.add(Restrictions.and(Restrictions.ge("waterDate", new java.sql.Timestamp(queryCrt.getStartDate().getTime())), Restrictions.le("waterDate", new java.sql.Timestamp(queryCrt.getEndDate().getTime()))));
		}else if(queryCrt.getStartDate()!=null&&queryCrt.getEndDate()==null){
			crt.add(Restrictions.ge("waterDate", new java.sql.Timestamp(queryCrt.getStartDate().getTime())));	
		}else if(queryCrt.getStartDate()==null&&queryCrt.getEndDate()!=null){
			crt.add(Restrictions.le("waterDate", new java.sql.Timestamp(queryCrt.getEndDate().getTime())));	
		}
//		if(queryCrt.getToComId()!=null&&queryCrt.getToComId()>0){			
//			crt.add(Restrictions.eq("comToId", queryCrt.getToComId()));
//		}
		if(queryCrt.getFromComId()!=null&&queryCrt.getFromComId()>0){			
			crt.add(Restrictions.eq("waterComId", queryCrt.getFromComId()));
		}

		if(queryCrt.getCarId()!=null&&queryCrt.getCarId()>0){			
			crt.add(Restrictions.eq("waterCarId", queryCrt.getCarId()));
		}

		if(queryCrt.getNum()!=null&&!(queryCrt.getNum().equalsIgnoreCase(""))){						
			crt.add(Restrictions.eq("num",queryCrt.getNum()));
		
		}
		if(queryCrt.getHeatNum()!=null&&!(queryCrt.getHeatNum().equalsIgnoreCase(""))){			
			crt.add(Restrictions.eq("waterNum", queryCrt.getHeatNum()));
		}
		//--权限判断,分公司只能看本公司单据，本部可以查看全部		
		if(loginUser.getZyncom().getComProperty().equalsIgnoreCase(Const.comTypetop)){			
			//总部
		}else{			
			crt.add(Restrictions.eq("extattrint4", loginUser.getComId()));  //匹配单据的所属公司
		}
		
		List<ZynBusiInputV> list = crt.list();
		return list;
	}
	
	/***
	 * 
	 * 单据列表明细
	 * 
	 * ***/
	/**
	 * 查找用
	 */

	public List<ZynBusiInputV> queryBillListByPage(int page, int rowsPerPage,ZynQueryCriter queryCrt) {
		
		ActionContext actionContext = ActionContext.getContext();         
	     Map session = actionContext.getSession(); 
	     ZynUser loginUser=(ZynUser)session.get("loginUser");   //登录用户		 
		
		String queryString = "from ZynBusiInputV";
		Transaction ts2=null;
		ts2=getSession().beginTransaction();
		getSession().clear(); 
		
		Criteria crt = getSession().createCriteria(ZynBusiInputV.class);
		crt.addOrder(org.hibernate.criterion.Order.desc("id"));
		
		if(queryCrt.getStartDate()!=null&&queryCrt.getEndDate()!=null){
			crt.add(Restrictions.and(Restrictions.ge("heatDate", new java.sql.Timestamp(queryCrt.getStartDate().getTime())), Restrictions.le("heatDate", new java.sql.Timestamp(queryCrt.getEndDate().getTime()))));
		}else if(queryCrt.getStartDate()!=null&&queryCrt.getEndDate()==null){
			crt.add(Restrictions.ge("heatDate", new java.sql.Timestamp(queryCrt.getStartDate().getTime())));	
		}else if(queryCrt.getStartDate()==null&&queryCrt.getEndDate()!=null){
			crt.add(Restrictions.le("heatDate", new java.sql.Timestamp(queryCrt.getEndDate().getTime())));	
		}
//		if(queryCrt.getToComId()!=null&&queryCrt.getToComId()>0){			
//			crt.add(Restrictions.eq("comToId", queryCrt.getToComId()));
//		}
		if(queryCrt.getFromComId()!=null&&queryCrt.getFromComId()>0){			
			crt.add(Restrictions.eq("heatComId", queryCrt.getFromComId()));
		}

		if(queryCrt.getCarId()!=null&&queryCrt.getCarId()>0){			
			crt.add(Restrictions.eq("heatCarId", queryCrt.getCarId()));
		}

		if(queryCrt.getNum()!=null&&!(queryCrt.getNum().equalsIgnoreCase(""))){						
			crt.add(Restrictions.eq("num",queryCrt.getNum()));
		
		}
		if(queryCrt.getHeatNum()!=null&&!(queryCrt.getHeatNum().equalsIgnoreCase(""))){			
			crt.add(Restrictions.eq("heatNum", queryCrt.getHeatNum()));
		}
		
		//--权限判断,分公司只能看本公司单据，本部可以查看全部
		
		if(loginUser.getZyncom().getComProperty().equalsIgnoreCase(Const.comTypetop)){			
			//总部
		}else{			
			crt.add(Restrictions.eq("extattrint4", loginUser.getComId()));  //匹配单据的所属公司
		}
		
		crt.setMaxResults(rowsPerPage); // 每页最多显示几条
		crt.setFirstResult((page - 1) * rowsPerPage); // 每页从第几条记录开始
		ts2.commit();
		List<ZynBusiInputV> list = crt.list();
		for (int i = 0; i < list.size(); i++) {			
			System.out.println("*****bill list****** id=:"+ list.get(i).getId()+list.get(i).getSellSts().getName());
		
		}
        
		return list;
	}
	/**
	 * 查找并返回所有计划
	 */

	public List<ZynBusiInputV> queryBillListtatolRows(ZynQueryCriter queryCrt) {
		
		ActionContext actionContext = ActionContext.getContext();         
	     Map session = actionContext.getSession(); 
	     ZynUser loginUser=(ZynUser)session.get("loginUser");   //登录用户		 
		
		getSession().clear();
		//Query query =getSession().createQuery("from ZynBusiInputV order by id desc");
		//query.setMaxResults(rowsPerPage); // 每页最多显示几条
		//query.setFirstResult((page - 1) * rowsPerPage); // 每页从第几条记录开始
		Criteria crt = getSession().createCriteria(ZynBusiInputV.class);
		crt.addOrder(org.hibernate.criterion.Order.desc("id"));
		

		if(queryCrt.getStartDate()!=null&&queryCrt.getEndDate()!=null){
			crt.add(Restrictions.and(Restrictions.ge("heatDate", new java.sql.Timestamp(queryCrt.getStartDate().getTime())), Restrictions.le("heatDate", new java.sql.Timestamp(queryCrt.getEndDate().getTime()))));
		}else if(queryCrt.getStartDate()!=null&&queryCrt.getEndDate()==null){
			crt.add(Restrictions.ge("heatDate", new java.sql.Timestamp(queryCrt.getStartDate().getTime())));	
		}else if(queryCrt.getStartDate()==null&&queryCrt.getEndDate()!=null){
			crt.add(Restrictions.le("heatDate", new java.sql.Timestamp(queryCrt.getEndDate().getTime())));	
		}
//		if(queryCrt.getToComId()!=null&&queryCrt.getToComId()>0){			
//			crt.add(Restrictions.eq("comToId", queryCrt.getToComId()));
//		}
		if(queryCrt.getFromComId()!=null&&queryCrt.getFromComId()>0){			
			crt.add(Restrictions.eq("heatComId", queryCrt.getFromComId()));
		}

		if(queryCrt.getCarId()!=null&&queryCrt.getCarId()>0){			
			crt.add(Restrictions.eq("heatCarId", queryCrt.getCarId()));
		}

		if(queryCrt.getNum()!=null&&!(queryCrt.getNum().equalsIgnoreCase(""))){						
			crt.add(Restrictions.eq("num",queryCrt.getNum()));
		
		}
		if(queryCrt.getHeatNum()!=null&&!(queryCrt.getHeatNum().equalsIgnoreCase(""))){			
			crt.add(Restrictions.eq("heatNum", queryCrt.getHeatNum()));
		}

		//--权限判断,分公司只能看本公司单据，本部可以查看全部		
		if(loginUser.getZyncom().getComProperty().equalsIgnoreCase(Const.comTypetop)){			
			//总部
		}else{			
			crt.add(Restrictions.eq("extattrint4", loginUser.getComId()));  //匹配单据的所属公司
		}
		
		List<ZynBusiInputV> list = crt.list();
		return list;
	}
	
	
}